package cn.wk.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCUtil {
    private static DataSource ds;
    static {

        try {
            Properties p=new Properties();
            InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties");
            p.load(is);
            try {
                ds= DruidDataSourceFactory.createDataSource(p);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static  DataSource getDataSource(){return ds;};

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }
}
